package blackhouse.advanced.code;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

public class CharDecode
{
	public static void main(String[] args)
	{
        System.out.println("please enter a chinese String:");
        byte[] buf = new byte[1024];
        String strInfo = null;
        int pos=0;
        int ch=0;
        while(true)
        {
			try
			{
				ch = System.in.read();
				System.out.println(Integer.toHexString(ch));
			} catch (IOException e)
			{
				e.printStackTrace();
			}
        	switch(ch)
        	{
        	case '\r':
        		break;
        	case   '\n':
				try
				{
					strInfo = new String(buf,0,pos,"gb2312");
				} catch (UnsupportedEncodingException e)
				{
					e.printStackTrace();
				}
        		for(int i=0;i<strInfo.length();i++){
        			 System.out.println(Integer.toHexString(strInfo.charAt(i)));
        		}
        		break;
        		default:
        			buf[pos++] =(byte)ch;
        	}
        }
	}

}
